package com.huawei.appmarket.service.settings.card;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant.KeyAndValue;
import huawei.widget.HwSwitch;
import o.cfw;
import o.cgz;
import o.cvt;
import o.der.d;
import o.der.f;
import o.dge;
import o.dgh;
import o.dgm;
import o.Logger;
import o.efx;
import o.egf.b;
import o.egl;
import o.egs;
import o.eqp;
import o.eua;
import o.euf;
import o.evk;

public class SettingPushSmsCardCard extends BaseSettingCard implements b, OnCheckedChangeListener {
    private View ˊ;
    protected HwSwitch ˋ;
    private boolean ˎ;
    protected boolean ˏ;
    private int ॱ;
    private egl ॱॱ;

    public SettingPushSmsCardCard(Context context) {
        super(context);
        ˋ();
    }

    protected void ˋ() {
        this.ˎ = eqp.ᐝ();
        if (!this.ˎ) {
            this.ॱॱ = new egl();
            this.ॱॱ.ˎ(this);
            this.ॱॱ.ˊ();
        }
    }

    public cgz ˏ(View view) {
        super.ˏ(view);
        this.ˋ = (HwSwitch) view.findViewById(d.ˇ);
        this.ˊ = view.findViewById(d.ʾᐝ);
        ((TextView) view.findViewById(d.ʽʼ)).setText(f.ˋᶥ);
        ˎ(view);
        ˎ();
        ʽ(view);
        return this;
    }

    protected void ˎ(View view) {
        if (this.ˎ) {
            ॱ(view);
        } else {
            ˊ(view);
        }
    }

    protected void ॱ(View view) {
        ((TextView) view.findViewById(d.ʽʻ)).setText(f.ˋꜞ);
    }

    protected void ˊ(View view) {
        ((TextView) view.findViewById(d.ʽʻ)).setText(f.ˋꞌ);
    }

    protected void ˎ() {
        this.ˏ = euf.ˎ().ˏ();
        if (this.ˋ != null) {
            this.ˋ.setChecked(this.ˏ);
            if (this.ˎ) {
                this.ˋ.setOnCheckedChangeListener(this);
                return;
            }
            this.ॱ = -1;
            this.ˋ.setChecked(false);
            this.ˋ.setEnabled(false);
            this.ˊ.setAlpha(0.3f);
        }
    }

    private void ˊ(boolean z) {
        ˎ(z);
        if (this.ᐝ != null) {
            Logger.ˏ("SettingPushSmsCardCard", "BI report");
            dgh.onEvent(new dge.d(this.ᐝ, f.ʻˊ).ˏ(z ? "02" : KeyAndValue.NUMBER_01).ˋ());
        }
    }

    protected void ˎ(boolean z) {
        try {
            String str = "";
            if (z) {
                str = efx.PUSH_ON;
            } else {
                str = efx.PUSH_OFF;
            }
            cvt o_efx = new efx(str);
            if (this.ᐝ instanceof Activity) {
                o_efx.setServiceType_(dgm.ˎ((Activity) this.ᐝ));
            }
            cfw.ˎ(o_efx, null);
        } catch (Exception e) {
            Logger.e("SettingPushSmsCardCard", "SettingPushSmsCardCard  uploadUserSettings method Exception =" + e.toString());
        }
    }

    protected void ॱ(boolean z) {
        euf.ˎ().ˎ(z);
        ˊ(z);
    }

    private void ˋ(boolean z) {
        ˊ(-1);
        this.ॱॱ.ॱ(z ? 1 : 0);
    }

    private void ˎ(int i, int i2) {
        ˊ(i2);
        if (i == 3) {
            Logger.ˋ("SettingPushSmsCardCard", "error to changeViewStatusByServer, responseCode = " + i);
            evk.ˋ(this.ʼॱ, this.ʼॱ.getString(f.ʻʽ), 0).ˋ();
        }
    }

    public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
        if (!ˏ(compoundButton)) {
            ˎ(compoundButton);
        }
    }

    private boolean ˏ(CompoundButton compoundButton) {
        if (egs.ॱ().ˏ(this.ᐝ) || !compoundButton.isChecked()) {
            return false;
        }
        egs.ॱ().ˋ(this.ᐝ).show();
        compoundButton.setChecked(false);
        return true;
    }

    protected void ˎ(CompoundButton compoundButton) {
        this.ˏ = compoundButton.isChecked();
        if (this.ˎ) {
            ॱ(this.ˏ);
        } else {
            ˋ(this.ˏ);
        }
    }

    public void ˊ(int i, int i2) {
        ˎ(i, i2);
    }

    public void ˋ(int i, int i2) {
        if (this.ॱ != i2) {
            if (this.ᐝ != null) {
                dgh.onEvent(new dge.d(this.ᐝ, f.ʻˊ).ˏ(i2 == 1 ? "02" : KeyAndValue.NUMBER_01).ˋ());
            }
            if (i2 == 1) {
                Logger.ˏ("SettingPushSmsCardCard", "oversea, open push switch");
                eua.ˏ().ˋ("oversea_push_agreement", true);
            }
        }
        ˎ(i, i2);
    }

    private void ˊ(int i) {
        Logger.ˏ("SettingPushSmsCardCard", "viewStatus = " + i);
        this.ˋ.setOnCheckedChangeListener(null);
        switch (i) {
            case 0:
                this.ˋ.setChecked(false);
                this.ˋ.setEnabled(true);
                this.ˏ = false;
                this.ॱ = 0;
                this.ˊ.setAlpha(1.0f);
                break;
            case 1:
                this.ˋ.setChecked(true);
                this.ˋ.setEnabled(true);
                this.ˏ = true;
                this.ॱ = 1;
                this.ˊ.setAlpha(1.0f);
                break;
            default:
                this.ˋ.setChecked(false);
                this.ˋ.setEnabled(false);
                this.ˊ.setAlpha(0.3f);
                break;
        }
        this.ˋ.jumpDrawablesToCurrentState();
        this.ˋ.setOnCheckedChangeListener(this);
    }
}
